#!/usr/bin/env bash

source ~/.bashrc
app_jar=schoolmate-home-server-0.0.1-SNAPSHOT.jar
echo use jdk $SDKMAN_DIR
# which sdk
sdk use java 17.0.9.fx-librca

# 获取进程 ID
pids=$(ps -ef | grep ${app_jar} | grep 'java' | awk '{print $2}')
# 检查是否有进程 ID
if [ -n "$pids" ]; then
    echo "killing process(${pids})..."
    kill $pids
fi

echo "starting..."
nohup java -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=heapdump.hprof -jar ${app_jar} >>out.log 2>&1 &
disown